﻿using System;
using HigLabo.Net.Extensions;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace HigLabo.Net.Twitter
{
    /// <summary>
    /// 
    /// </summary>
    public class RetweetedStatus : ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        public BoundingBox Coordinates { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset CreatedAt { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Favorited { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Truncated { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String IDString { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String InReplyToUserIDString { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Entities Entities { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String Text { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public List<Int64> Contributors { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int64 ID { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 RetweetCount { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String InReplyToStatusIDString { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String Geo { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Retweeted { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int64 InReplyToUserID { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String Source { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String InReplyToScreenName { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public User User { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Place Place { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int64 InReplyToStatusID { set; get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public RetweetedStatus(String jsonText)
        {
            this.SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public override void SetProperty(string jsonText)
        {
            var d = this.SetData(jsonText);

            if (!String.IsNullOrEmpty(d.ToString("contributors")))
            {
                this.Contributors = new List<Int64>();
                var cc = JsonConvert.DeserializeObject(d.ToString("contributors")) as JContainer;
                foreach (var i in cc)
                {
                    this.Contributors.Add(Convert.ToInt64(i.ToString()));
                }
            }
            this.Coordinates = new BoundingBox(d.ToString("coordinates"));
            this.CreatedAt = d.CastToDateTimeOffset("created_at") ?? this.CreatedAt;
            this.Entities = new Entities(d.ToString("entities"));
            this.Favorited = d.ToBoolean("favorited") ?? this.Favorited;
            this.Geo = d.ToString("geo");
            this.ID = d.ToInt64("id") ?? 0;
            this.IDString = d.ToString("id_str");
            this.InReplyToScreenName = d.ToString("in_reply_to_screen_name");
            this.InReplyToStatusID = d.ToInt64("in_reply_to_status_id") ?? 0;
            this.InReplyToStatusIDString = d.ToString("in_reply_to_status_id_str");
            this.InReplyToUserID = d.ToInt64("in_reply_to_user_id") ?? 0;
            this.InReplyToUserIDString = d.ToString("in_reply_to_user_id_str");
            this.Place = new Place(d.ToString("place"));
            this.RetweetCount = d.ToInt32("retweet_count") ?? 0;
            this.Retweeted = d.ToBoolean("retweeted") ?? this.Retweeted;
            this.Source = d.ToString("source");
            this.Text = d.ToString("text");
            this.Truncated = d.ToBoolean("truncated") ?? this.Truncated;
            this.User = new User(d.ToString("user"));
        }
    }
}
